home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / sot.zip / SOTM.C < prev    next >
Text File  |  1988-08-23  |  5KB  |  194 lines

  1. /********** The Son of Tetris Project ************/
  2.  
  3. /************  MANIPULATION of SHAPES ***********/
  4.  
  5. #include <assert.h>
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10.  
  11. #include "sot.h"
  12.  
  13. #define DELAY_TIME 25 /* Loop, unit of time */
  14. #define DONT_CARE 0   /* For unused parameter */
  15. #define HOT_LEVEL 4  /* Level at which hot objects start to appear */
  16. #define MAX_HEAT 4  /* Maximum heat */
  17.  
  18. void  or_obj(SHP_TYPE *sh, int *a_ht, int *a_wd, int orient)
  19. /* Set object orientation */
  20. {
  21.   if (orient & 1)
  22.   {
  23.     *a_wd = sh->ht; *a_ht = sh->wd;
  24.   } /* rotated 90/270 */
  25.   else
  26.   {
  27.     *a_wd = sh->wd; *a_ht = sh->ht;
  28.   } /* rotated 0/180 */
  29. }     /* or_obj */
  30.  
  31.  
  32.  
  33. int  shp_pos(SHP_TYPE *sh, int  x_pos, int  y_pos,
  34.              int orient, int temperature, sh_op_type fn)
  35. {
  36.   int        i,j, a_wd, a_ht, *map_ptr;
  37.   unsigned  val, test_val = 0;
  38.  
  39.   or_obj(sh, &a_ht, &a_wd, orient);   /* get ht and width correct */
  40.   map_ptr = sh->map[orient];          /* set orientation of shape */
  41.  
  42.   switch(fn)
  43.   {
  44.     case test:
  45.       for (i = y_pos; i < a_ht + y_pos; i++)
  46.         for (j = x_pos; j < a_wd + x_pos; j++, map_ptr++)
  47.           if ((val = arena[j][i]) && *map_ptr  /* clash exists at this point */
  48.           && (val > test_val))
  49.         test_val = val;
  50.       break;
  51.  
  52.     case insert:
  53.       for (i = y_pos; i < a_ht + y_pos; i++)
  54.         for (j = x_pos; j < a_wd + x_pos; j++, map_ptr++)
  55.       if (*map_ptr)  /* i.e. shape exists at this point */
  56.         if (temperature)
  57.               arena[j][i] = sh->col | BLINK;
  58.         else  /* cold! */
  59.               arena[j][i] = sh->col;
  60.       break;
  61.  
  62.  
  63.     case remve:
  64.       for (i = y_pos; i < a_ht + y_pos; i++)
  65.         for (j = x_pos; j < a_wd + x_pos; j++, map_ptr++)
  66.           if (*map_ptr)  /* i.e. shape exists at this point */
  67.         arena[j][i] = CLEAR;
  68.       break;
  69.   } /* switch */
  70.   return(test_val);
  71. }     /*  shp_pos */
  72.  
  73.  
  74. int    mv(drctn_type dt, OBJ_TYPE *cur_obj, int amt)
  75. {
  76.   int x, y,
  77.       or,
  78.       disp_left, disp_right,
  79.       disp_top,disp_bot,
  80.       wd, ht,
  81.       display,
  82.       result;
  83.   SHP_TYPE *shp;
  84.  
  85.   shp = cur_obj->o_sh;
  86.   or_obj(shp, &ht, &wd, cur_obj -> o_or);   /* get ht and width correct */
  87.  
  88.   disp_left = cur_obj->o_x;
  89.   disp_right = cur_obj->o_x + wd - 1;
  90.   disp_top = cur_obj->o_y;
  91.   disp_bot = cur_obj->o_y + ht - 1;
  92.   switch(dt)
  93.   {
  94.     case left:
  95.       x = cur_obj->o_x - amt;
  96.       y = cur_obj->o_y;
  97.       or = cur_obj -> o_or;
  98.       disp_left -= amt;
  99.       break;
  100.  
  101.     case down:
  102.       x = cur_obj->o_x;
  103.       y = cur_obj->o_y + amt;
  104.       or = cur_obj -> o_or;
  105.       disp_bot += amt;
  106.       break;
  107.  
  108.     case right:
  109.       x = cur_obj->o_x + amt;
  110.       y = cur_obj->o_y;
  111.       or = cur_obj -> o_or;
  112.       disp_right += amt;
  113.       break;
  114.  
  115.     case anti:
  116.       x = cur_obj->o_x ;
  117.       y = cur_obj->o_y ;
  118.       or = (cur_obj -> o_or + 1) & 3;
  119.       disp_right = disp_bot = (ht > wd) ? ht : wd;
  120.       disp_right += x; disp_bot += y;
  121.       break;
  122.  
  123.     case clock:
  124.  
  125.     default:
  126.       assert(FALSE);
  127.  
  128.   } /* switch */
  129.  
  130.   shp_pos(cur_obj->o_sh, cur_obj->o_x, cur_obj->o_y,
  131.       cur_obj->o_or, DONT_CARE, remve);
  132.   display = !(result = shp_pos(cur_obj->o_sh, x, y, or, DONT_CARE, test));
  133.  
  134.   if (!result)  /* ok to move */
  135.   {
  136.     cur_obj->o_x = x;
  137.     cur_obj->o_y = y;
  138.     cur_obj->o_or = or;
  139.   }
  140.   else
  141.   if ( (cur_obj->o_temp) && (result < BORDER) ) /* object is hot */
  142.   {
  143.     cur_obj->o_x = x;
  144.     cur_obj->o_y = y;
  145.     cur_obj->o_or = or;
  146.     cur_obj->o_temp--;     /* cool object down */
  147.     result = 0; /* hot object has moved: force result */
  148.     display = TRUE;
  149.   }
  150.   else
  151.   if ((cur_obj->o_temp) && (dt == down))
  152.   {
  153.     cur_obj->o_temp = 0;
  154.     display = TRUE; /* force display of cool object */
  155.   }
  156.  
  157.   shp_pos(cur_obj->o_sh, cur_obj->o_x, cur_obj->o_y,
  158.              cur_obj->o_or, cur_obj->o_temp, insert);
  159.  
  160.   if (display)  /* display shape as moved */
  161.   {
  162.     p_arena(disp_left,disp_top,disp_right,disp_bot);
  163.   }
  164.  
  165.   return(result);
  166. } /* mv */
  167.  
  168.  
  169. int    insrt(OBJ_TYPE *cur_obj,SHP_TYPE *next_sh, int level)
  170. { /* Set up new falling object if possible */
  171.   SHP_TYPE *sh;
  172.   int  result;
  173.  
  174.   #define TOP 1
  175.  
  176.   sh = cur_obj->o_sh = next_sh;
  177.   cur_obj->o_x = (BLW/2) - (sh->wd / 2); /* in the middle */
  178.   cur_obj->o_or = 0; /* Default orientation is upright */
  179.   cur_obj->o_y =  TOP;
  180.   cur_obj->o_temp = 0;  /* Cold */
  181.   if ( (level > HOT_LEVEL) & !(rand() % 4) )
  182.     cur_obj->o_temp = MAX_HEAT;
  183.  
  184.   result = shp_pos(cur_obj->o_sh, cur_obj->o_x, cur_obj->o_y,
  185.                     cur_obj->o_or,  DONT_CARE, test);
  186.   shp_pos(cur_obj->o_sh, cur_obj->o_x, cur_obj->o_y,
  187.                   cur_obj->o_or,  cur_obj->o_temp, insert);
  188.   p_arena(cur_obj->o_x,TOP,cur_obj->o_x + sh -> wd - 1,TOP +sh -> ht -1);
  189.   return(result);
  190. } /* insrt */
  191.  
  192.  
  193.  
  194.